package net.borlis.sample.web.context.mock;

import net.borlis.dictionaries.product.HierarchyLevelDictionary;
import net.borlis.dictionaries.product.LifecycleStateDictionary;
import net.borlis.sample.entities.enumerated.BookingStrategy;
import net.borlis.sample.services.catalog.protocol.*;
import net.borlis.sample.services.declaration.CatalogService;
import net.borlis.sample.services.declaration.common.CountryObject;
import net.borlis.sample.services.declaration.common.CurrencyObject;
import net.borlis.sample.services.declaration.common.LocaleObject;
import net.borlis.sample.services.declaration.output.BookingConfigStrategyObject;
import net.borlis.sample.services.declaration.output.CountryCurrencyObject;
import net.borlis.sample.services.declaration.output.CreditCardTypeObject;
import net.borlis.sample.services.declaration.output.HierarchyLevelObject;
import net.borlis.sample.services.payment.common.StandardCreditCardTypeObject;
import net.borlis.errors.annotations.ServerExceptionRegister;
import net.borlis.log.SimpleLogger;

import javax.enterprise.inject.Alternative;
import javax.persistence.NoResultException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author alex@borlis.net
 */
@Alternative
public class MockCatalogService implements CatalogService {

    public static final List<LocaleObject> MOCK_LOCALES = new ArrayList<>();
    static {
        LocaleObject localeDE = new Language(1, "de-DE", "Deutch");
        MOCK_LOCALES.add(localeDE);
        LocaleObject localeEN = new Language(1, "en-GB", "English");
        MOCK_LOCALES.add(localeEN);
    }

    public static final List<CountryCurrencyObject> MOCK_EN_COUNTRIES = new ArrayList<>();
    static {
        CurrencyObject euro = new Currency(1, "EUR", "Euro");
        CountryObject de = new Country(1, "DE", "Germany");
        CountryObject en = new Country(1, "EN", "England");
        CountryCurrencyObject germany = new CountryCurrency(de, euro);
        MOCK_EN_COUNTRIES.add(germany);
        CountryCurrencyObject england = new CountryCurrency(en, euro);
        MOCK_EN_COUNTRIES.add(england);
    }

    public static final List<HierarchyLevelObject> MOCK_DE_HIERARCHIES = new ArrayList<>();
    static {
        HierarchyLevelObject defaultSettingsDE = new HierarchyLevel(HierarchyLevelDictionary.DEFAULT_SETTING, "Default settings");
        MOCK_DE_HIERARCHIES.add(defaultSettingsDE);
        HierarchyLevelObject providerSettingsDE = new HierarchyLevel(HierarchyLevelDictionary.PROVIDER_SETTING, "Provider settings");
        MOCK_DE_HIERARCHIES.add(providerSettingsDE);
    }


    @Override @SimpleLogger
    @ServerExceptionRegister(code = "632", logMessage = "locales list cannot be returned",
            expected = {NullPointerException.class, NoResultException.class})
    public List<LocaleObject> getAllLocales() {
        return MOCK_LOCALES;
    }

    /**
     * {@inheritDoc}
     */
    @Override @SimpleLogger
    @ServerExceptionRegister(code = "631", logMessage = "countries list cannot be returned",
            expected = {NullPointerException.class, NoResultException.class})
    public List<CountryCurrencyObject> getAllCountries(String locale) /* throws ServerException */ {
        return MOCK_EN_COUNTRIES;
    }

    /**
     * {@inheritDoc}
     */
    @Override @SimpleLogger
    @ServerExceptionRegister(code = "633", logMessage = "credit card types list cannot be returned",
            expected = {NullPointerException.class, NoResultException.class})
    public List<CreditCardTypeObject> getCreditCardTypes(String locale) /* throws ServerException */ {
        return new ArrayList<CreditCardTypeObject>(StandardCreditCardTypeObject.CARD_TYPES.values());
    }

    /**
     * {@inheritDoc}
     */
    @Override @SimpleLogger
    @ServerExceptionRegister(code = "634", logMessage = "booking strategies list cannot be returned",
            expected = {NullPointerException.class, NoResultException.class})
    public List<BookingConfigStrategyObject> getBookingConfigStrategies(String locale) /* throws ServerException */ {
        List<BookingConfigStrategyObject> result = new ArrayList<>();
        for (BookingStrategy bs : BookingStrategy.values()) {
            result.add(new BookingConfigStrategy(bs.ordinal(), bs.name(), bs.getLabel()));
        }
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override @SimpleLogger
    @ServerExceptionRegister(code = "635", logMessage = "hierarchy levels list cannot be returned",
            expected = {NullPointerException.class, NoResultException.class})
    public List<HierarchyLevelObject> getHierarchyLevels(String locale) /* throws ServerException */ {
        return MOCK_DE_HIERARCHIES;
    }

    @Override
    public void findAndInitDynamixAccountById(Number userId) {

    }

    @Override
    public void findAndInitVitoById(LifecycleStateDictionary state, Number vitoId) {

    }
}
